﻿using System;
using System.ComponentModel;
using EasyNetQ;
using EasyNetQ.Consumer;
using ZL.Web.Utility.Config;

namespace ZL.Web.Utility.MQ
{
    public class BusBuilder
    {
        public static IBus CreateMessageBus()
        {
            // 消息服务器连接字符串
            // var connectionString = ConfigurationManager.ConnectionStrings["RabbitMQ"];
            string connString = ZLConfig.RabbitConnection;
            if (connString == null || connString == string.Empty)
            {
                throw new Exception("messageserver connection string is missing or empty");
            }

            //CrmDefaultConsumerErrorStrategy errorStategy = new CrmDefaultConsumerErrorStrategy();
            return RabbitHutch.CreateBus(connString,tr => tr.Register<IConsumerErrorStrategy, CrmDefaultConsumerErrorStrategy>());
        }
    }
}
